package com.yanqu.road.server.cmd.union.cross.honors;

import com.yanqu.road.pb.union.UnionProto;
import com.yanqu.road.pb.union.cross.CrossUnionHonorsProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.union.CrossUnionMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

@Cmd(code = Protocol.C_UNION_CHANGE_FLAG_NEW, desc = "修改商会旗帜")
public class CrossUnionModifyFlagNewCmd extends CrossCommand {

    long playerId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        playerId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        CrossUnionHonorsProto.CrossUnionModifyFlagReqMsg reqMsg = CrossUnionHonorsProto.CrossUnionModifyFlagReqMsg.parseFrom(packet.getBytes());
        List<Integer> flagList = reqMsg.getUnionFlagList();

        ret = CrossUnionMgr.changeUnionFlag(serverId, packet.getPlayerId(), flagList);
    }

    @Override
    public void sendData() {
        if(ret != 0){
            CrossUnionHonorsProto.CrossUnionModifyFlagRespMsg.Builder respMsg = CrossUnionHonorsProto.CrossUnionModifyFlagRespMsg.newBuilder();
            respMsg.setRet(ret);
            MessageHelper.sendPacket(serverId, playerId, YanQuMessageUtils.buildMessage(Protocol.U_UNION_CHANGE_FLAG_NEW, respMsg));
        }
    }
}
